package com.example.demo.service;

import com.example.demo.entity.InstrumentCollection;
import com.example.demo.entity.TheoryKnowledgeCollection;
import com.example.demo.mapper.InstrumentCollectionMapper;
import com.example.demo.mapper.TheoryKnowledgeCollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TheoryKnowledgeCollectionImpl  implements TheoryKnowledgeCollectionService{

    @Autowired
    private TheoryKnowledgeCollectionMapper theoryKnowledgeCollectionMapper;

    @Override
    public boolean addCollection(TheoryKnowledgeCollection theoryKnowledgeCollection) {
        return theoryKnowledgeCollectionMapper.addCollection(theoryKnowledgeCollection) > 0;
    }

    // 删除收藏（修改后接收 InstrumentCollection 对象）
    @Override
    public boolean deleteCollection(TheoryKnowledgeCollection theoryKnowledgeCollection) {
        return theoryKnowledgeCollectionMapper.deleteCollection(theoryKnowledgeCollection.getUser_id(), theoryKnowledgeCollection.getTheory_knowledge_id()) > 0;
    }

    @Override
    public List<TheoryKnowledgeCollection> getCollectionsByUserId(Integer userId) {
        return theoryKnowledgeCollectionMapper.getCollectionsByUserId(userId);
    }

    @Override
    public boolean isCollected(Integer userId, Integer theoryKnowledgeId) {
        return theoryKnowledgeCollectionMapper.checkIfCollected(userId, theoryKnowledgeId) > 0;
    }

    //点击量
    @Override
    public Integer clickViewCount(Integer theoryKnowledgeId) {
        return theoryKnowledgeCollectionMapper.clickViewCount(theoryKnowledgeId);
    }
}
